<template>
  <div class="content-box">
    <nav-title title="联系方式" />
    <edit-line label="手机号码" :important="true" v-model="basicInfo.phone"></edit-line>
    <edit-line label="传真" v-if="basicInfo.platLx== '10'" v-model="basicInfo.cFax"></edit-line>
    <edit-line label="个人Email" v-if="basicInfo.platLx== '10'" v-model="basicInfo.emailAddr"></edit-line>
    <edit-line label="公司电话" v-if="basicInfo.platLx== '10'" v-model="basicInfo.phone2"></edit-line>
    <edit-line label="紧急联系人" :important="true" v-model="basicInfo.emeContract"></edit-line>
    <edit-option-line :important="true" label="与本人关系" :vals="relations" v-model="basicInfo.cRelationFam"></edit-option-line>
    <edit-line label="联系人电话" :important="true" v-model="basicInfo.emePhone"></edit-line>
    <div class="bsbtn" @click="save">保存</div>
    <div stype="width:100%;height:30px">&nbsp;</div>
  </div>

</template>

<script>
import { Datetime, Group, PopupRadio } from 'vux'
import CommonUtil from '../../../../components/basic/util'
import EditLine from '../../../../components/basic/EditLine'
import EditOptionLine from '../../../../components/basic/EditOptionLine'
import { getDicItem, saveConcatInfo, getIdType, getQrmsg } from '../../../../api/api'
import { json2Form } from '../../../../util/http'

export default {

  name: 'input-information',
  components: {
    EditLine,EditOptionLine
  },
  mounted(){
    if(this.$store.state.hid){
      this.basicInfo.rsHireId = this.$store.state.hid
    }
    CommonUtil.loadDic(this.relations, 'C_RELATION_FAM', "xlatshortname","fieldvalue");//亲属关系
  },
  data() {
    return {
      basicInfo:{},
      relations:[]
    }
  },
  created() {
    this.getBsif()
  },
  methods: {
    save() {
      var that = this
      console.log(this.basicInfo)
      
      if(!CommonUtil.valid(this, this.basicInfo,"phone","请输入手机号") 
        || !CommonUtil.valid(this, this.basicInfo,"emeContract","请输入紧急联系人姓名") 
        || !CommonUtil.valid(this, this.basicInfo,"cRelationFam","请输入紧急联系人关系") 
        || !CommonUtil.valid(this, this.basicInfo,"emePhone","请输入紧急联系人电话") 
        ){
        return;
      }
      if(!CommonUtil.checkPhone(this.basicInfo.phone)) {
        this.$vux.alert.show({
          title: '提示',
          content: '请输入正确的手机号',
        })
        return;
      }
      if(!CommonUtil.checkPhone(this.basicInfo.emePhone)) {
        this.$vux.alert.show({
          title: '提示',
          content: '请输入正确的联系人电话',
        })
        return;
      }
      if(this.basicInfo.emailAddr && !CommonUtil.checkMail(this.basicInfo.emailAddr)) {
        this.$vux.alert.show({
          title: '提示',
          content: '请输入正确的邮箱号',
        })
        return;
      }
      if(this.basicInfo.phone == this.basicInfo.emePhone) {
        this.$vux.alert.show({
          title: '提示',
          content: '联系人电话与本人联系方式不能相同',
        })
        return;
      }

      console.log(that.basicInfo)
      saveConcatInfo(json2Form(that.basicInfo)).then(res => {
        if(res && res.retCode === '000000' ){
          //保存成功
          this.$vux.alert.show({
            title: '提示',
            content: '保存成功',
            onHide () {
              that.$router.push('/informationCollection/userInfo');
            }
          })

        }else{
          // 显示
          this.$vux.alert.show({
            title: '提示',
            content: res.retMsg
          })
        }
      }).catch (res=>{
        this.$vux.alert.show({
          title: '警告',
          content: '网络异常，请稍后重试'
        })
      })
    },

    getBsif() {
      if(this.$route.params.bsifs){
        this.basicInfo = this.$route.params.bsifs
        this.hideTwo = this.$route.params.whc
      }
    }
  },
  watch: {
    '$route': 'getBsif'
  }
}
</script>
<style type="text/scss" lang="scss">
  @import "./editinfo";
</style>
